import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/pages/Home.vue'
import Category from '@/pages/Category.vue'
import Shopcart from '@/pages/Shopcart.vue'
import User from '@/pages/User.vue'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
  { path: '/', name: 'home', redirect: '/home' },
  { path: '/', redirect: '/home', meta: { title: '⾸⻚' } },
  { path: '/home', component: Home, name: 'home', meta: { title: '⾸⻚' } },
  { path: '/category', component: Category, name: 'category', meta: { title: '分类' } },
  { path: '/shopcart', component: Shopcart, name: 'shopcart', meta: { title: '购物⻋' } },
  { path: '/user', component: User, name: 'user', meta: { title: '我的' } }
]
})
router.beforeEach((to, from, next) => {
  //判断当前路由meta.title是否为空，不空，设置⽂档标题
  if (to.meta.title) {
  document.title = to.meta.title
   }
  //放⾏
  next()
})
export default router